﻿#pragma once 


#include <iostream>
#include <onnxruntime_cxx_api.h>
#include "humanseg_base.h"

using namespace Ort;
using namespace std;

class RVMHumanSegOrt: public HumanSegBase
{
public:
	RVMHumanSegOrt(const char *model_name, int model_width, int model_height, int is_video, int enable_debug);
	~RVMHumanSegOrt();
public:
	int detect_rgb24_do(unsigned char *buf_rgb, int src_pitch, unsigned char *alpha, int alpha_pitch);

private:
    Env env_;
	Ort::Session *ort_session_ ;
	SessionOptions sessionOptions_; 
 	vector<char*> input_names_;
	vector<char*> output_names_;

	vector<vector<int64_t>> input_node_dims_; // >=1 outputs
	vector<vector<int64_t>> output_node_dims_; // >=1 outputs   
    float *src_net_in_;
    uint16_t *src_net_in_fp16_;

    int32_t         i_fp16_;
    float           downsample_ratio_;
    int32_t         num_inputs_;
    int32_t         num_outputs_;    

	vector<uint16_t> dynamic_r1i_value_handler_fp16_ ; // init 0. with shape (1,1,1,1)
	vector<uint16_t> dynamic_r2i_value_handler_fp16_ ;
	vector<uint16_t> dynamic_r3i_value_handler_fp16_ ;
	vector<uint16_t> dynamic_r4i_value_handler_fp16_ ;
    

    
	vector<float> dynamic_r1i_value_handler_ ; // init 0. with shape (1,1,1,1)
	vector<float> dynamic_r2i_value_handler_ ;
	vector<float> dynamic_r3i_value_handler_ ;
	vector<float> dynamic_r4i_value_handler_ ;
	vector<float> dynamic_dsr_value_handler_ ; // downsample_ratio with shape (1)    

    vector<vector<int64_t>> dynamic_input_node_dims_;
    
private:
	int64_t value_size_of(const std::vector<int64_t> &dims);
	void transform( std::vector<Ort::Value> & input_tensors);
	void update_context(vector<Ort::Value> &output_tensors);    
};